#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

struct student
{
    int c;
    int m;
    int e;
}stu[1000];

int judge(struct student a, struct student b)
{
    if (abs(a.c - b.c) > 5) return 0;
    if (abs(a.m - b.m) > 5) return 0;
    if (abs(a.e - b.e) > 5) return 0;
    if (abs(a.c + a.m + a.e - b.c - b.m - b.e) > 10) return 0;
    return 1;
}

int main()
{
    int n = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d%d%d", &stu[i].c, &stu[i].m, &stu[i].e);
    int count = 0;
    for (int i = 1; i < n; i++)
        for (int j = i + 1; j <= n; j++)
            if (judge(stu[i], stu[j]) == 1)
                count++;
    printf("%d", count);
    return 0;
}